﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Iservices;
using Model;
using EFEntity;
using System.Linq;
using AutoMapper;
using Microsoft.EntityFrameworkCore;

namespace Services
{
    public class Ssalary_standard_details : lsalary_standard_details
    {
        private readonly MyDbContext mydb;
        private readonly IMapper mapper;
        public Ssalary_standard_details(MyDbContext mydb, IMapper mapper)
        {
            this.mydb = mydb;
            this.mapper = mapper;
        }

        public async Task<int> Salaryadd(salary_standard_details s)
        {
            
            Esalary_standard_details etest = mapper.Map<Esalary_standard_details>(s);
            mydb.alary.Add(etest);
            int reslut = await mydb.SaveChangesAsync();
            return reslut;

        }

        public async Task<int> SalaryDel(int sid)
        {
            Esalary_standard_details s = new Esalary_standard_details();
            s = mydb.alary.Find(sid);
            mydb.alary.Remove(s);
            int reslut = await mydb.SaveChangesAsync();
            return reslut;

        }

        public async Task<List<salary_standard_details>> Select()
        {
            List<Esalary_standard_details> list = new List<Esalary_standard_details>();
            await Task.Run(() =>
            {
                list = mydb.alary.ToList();
            });
            List<salary_standard_details> list2 = mapper.Map<List<salary_standard_details>>(list);
            return list2;

        }

        public async Task<int> Update(salary_standard_details b)
        {
            Esalary_standard_details etest = mapper.Map<Esalary_standard_details>(b);
            mydb.Attach(etest);
            mydb.Entry<Esalary_standard_details>(etest).State = EntityState.Modified;
            return await mydb.SaveChangesAsync();
        }

    }
}
